<template>
    <!-- pages/gatheringAuth/index.wxml -->
    <view>
        <view class="titie">申请开通门店收款码：</view>
        <view class="flexbox-sb authbox">
            <view>
                <view class="auth_name">商户资料认证</view>
                <view class="auth_user" v-if="incomingInfo.isRealName == 1">请法人填写资料进行认证</view>
                <view class="auth_user" v-if="(incomingInfo.status == 3 || incomingInfo.status == 5) && incomingInfo.isRealName == 2">
                    失败原因：{{ incomingInfo.auditResult }}
                </view>
                <view class="auth_user mt-20" v-if="incomingInfo.status < 3 && incomingInfo.isRealName == 2">已提交。审核周期一般为两到三个工作日，请耐心等待</view>
            </view>
            <view class="text-r" v-if="incomingInfo.isRealName == 1">未认证</view>
            <view class="text-r" v-if="incomingInfo.status < 3 && incomingInfo.isRealName == 2">审核中</view>
            <view class="text-r" v-if="incomingInfo.status == 6 && incomingInfo.isRealName == 2">审核中</view>
            <view class="text-r" v-if="incomingInfo.status == 4 && incomingInfo.isRealName == 2">已认证</view>
            <view class="text-r" v-if="(incomingInfo.status == 3 || incomingInfo.status == 5) && incomingInfo.isRealName == 2">审核失败</view>
            <view class="btn" @tap.stop.prevent="onLoad" v-if="incomingInfo.status == 4 && incomingInfo.isRealName == 2">刷新</view>
            <view class="btn" @tap.stop.prevent="goMain" v-if="(incomingInfo.status == 3 || incomingInfo.status == 5) && incomingInfo.isRealName == 2">重新申请</view>
            <view class="btn" @tap.stop.prevent="goMain" v-if="incomingInfo.isRealName == 1">申请认证</view>
        </view>
        <view class="authbox">
            <view class="flexbox-sb">
                <view>
                    <view class="auth_name l-90">微信商户认证</view>
                    <!-- <view class="auth_user">请法人使用微信扫码实名认证，若未认证将无法使用微信收款；</view> -->
                </view>
                <view class="text-r" v-if="incomingInfo.wechatVerifyState != 1">未认证</view>
                <view class="text-r" v-if="incomingInfo.wechatVerifyState == 1">已认证</view>
                <view :class="incomingInfo.status != 4 ? 'btn1' : 'btn'" @tap.stop.prevent="goWxCode" v-if="incomingInfo.wechatVerifyState != 1">申请认证</view>
            </view>
            <view class="auth_msg">该认证为微信平台支付认证，认证通过后才能使用微信收款。</view>
            <view class="auth_msg">1、请法人使用微信扫码实名认证；</view>
            <view class="auth_msg">
                2、认证商户名称必须与【
                <text style="color: red">{{ incomingInfo.mchtName || '商户资料认证' }}</text>
                】名称保持一致；
            </view>
            <view class="auth_msg">3、如已经提交，等待腾讯公司审核，点击下方刷新可查看最新状态。</view>
        </view>
        <view class="authbox">
            <view class="flexbox-sb">
                <view>
                    <view class="auth_name l-90">支付宝商户认证</view>
                    <!-- <view class="auth_user">请法人使用支付宝扫码实名认证，若未认证将无法使用支付宝收款；</view> -->
                </view>
                <view class="text-r" v-if="incomingInfo.aliVerifyState != 1">未认证</view>
                <view class="text-r" v-if="incomingInfo.aliVerifyState == 1">已认证</view>
                <view :class="incomingInfo.status != 4 ? 'btn1' : 'btn'" @tap.stop.prevent="goZfbCode" v-if="incomingInfo.aliVerifyState != 1">申请认证</view>
            </view>
            <view class="auth_msg">该认证为支付宝平台支付认证，认证通过后才能使用支付宝收款。</view>
            <view class="auth_msg">1、请法人使用支付宝扫码实名认证；</view>
            <view class="auth_msg">
                2、认证商户名称必须与【
                <text style="color: red">{{ incomingInfo.mchtName || '商户资料认证' }}</text>
                】名称保持一致；
            </view>
            <view class="auth_msg">3、如已经提交，等待阿里公司审核，点击下方刷新可查看最新状态。</view>
        </view>
        <!-- 是否已申请开通分账 1-未 申请 2-已申请/待开通 3 待盒子审核 4 已开通 5 开通失败', -->
        <view class="flexbox-sb authbox" v-if="incomingInfo.status == 4">
            <view>
                <view class="auth_name">收款认证</view>
                <view class="auth_user" v-if="incomingInfo.openAccountStatus == 1">您的收款账号为{{ incomingInfo.mchtNo }}，暂未进行收款认证</view>
            </view>
            <view class="text-r" v-if="incomingInfo.openAccountStatus == 1">未认证</view>
            <view class="text-r" v-if="incomingInfo.openAccountStatus == 2 || incomingInfo.openAccountStatus == 3">审核中</view>
            <view class="text-r" v-if="incomingInfo.openAccountStatus == 4">已认证</view>
            <view class="text-r" v-if="incomingInfo.openAccountStatus == 5">开通失败</view>
            <view class="btn" @tap.stop.prevent="applyForOpeningAnAccount" v-if="incomingInfo.openAccountStatus == 1">申请认证</view>
        </view>
        <view class="refresh" @tap.stop.prevent="onLoad">刷新认证状态</view>
    </view>
</template>

<script>
// pages/gatheringAuth/index.js
const app = getApp();

const _request = require('../../utils/request.js'); // 引入require;

export default {
    data() {
        return {
            incomingInfo: null,
            applyInfo: null,
            instanceInfo: null // 二审数据
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        let id = '';

        if (options.storeId) {
            uni.setStorageSync('crm_storeId', options.storeId);
            id = options.storeId;
            uni.hideHomeButton({
                complete: () => {
                    console.log('成功');
                }
            });
        } else {
            id = uni.getStorageSync('storeId');
        }

        _request
            .postObj(
                '/mall-product/shareposter',
                {
                    productInfoUrl: '/firstpages/home/index',
                    type: 3
                },
                app.globalData.mallType
            )
            .then((res) => {
                this.getIncoming(id);
            });

        _request
            .get('/box/refreshAuthenticationStatus', {
                storeId: uni.getStorageSync('storeId')
            })
            .then((res) => {});

        this.getinstanceInfo();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        // 申请验证
        goMain() {
            const { instanceInfo, incomingInfo } = this;
            let main;
            let account; // 是否二审状态 0-否 1-是

            if (incomingInfo.isSecondTrialStatus == 1 && instanceInfo.code == 3) {
                const { licenceType, channelKind, accountType, accountProxy } = incomingInfo;

                if (licenceType == 0) {
                    main = '企业';

                    if (accountType == 0) {
                        account = '对公';
                    } else {
                        if (accountProxy == '1') {
                            account = '非法人';
                        } else {
                            account = '法人';
                        }
                    }
                } else {
                    if (channelKind == '000001') {
                        main = '小微商户';
                        account = '法人';
                    } else {
                        main = '个体';

                        if (accountType == 0) {
                            account = '对公';
                        } else {
                            if (accountProxy == '1') {
                                account = '非法人';
                            } else {
                                account = '法人';
                            }
                        }
                    }
                }

                uni.navigateTo({
                    url: '/pages/gatheringAuth/auths/index?main=' + main + '&account=' + account
                });
            } else {
                uni.navigateTo({
                    url: '/pages/gatheringAuth/businessMain/index'
                });
            }
        },

        // 申请开通分账
        applyForOpeningAnAccount() {
            _request
                .postObj('/box/applyForOpeningAnAccount', {
                    shopId: this.incomingInfo.shopId
                })
                .then((res) => {
                    if (res.data.code === 200) {
                        const data = res.data.data;
                        this.getIncoming(uni.getStorageSync('crm_storeId') || uni.getStorageSync('storeId'));
                        this.setData({
                            applyInfo: data
                        });
                    }
                });
        },

        // wx实名认证
        goWxCode() {
            if (this.incomingInfo.status != 4) {
                uni.showToast({
                    title: '请先完成商户认证',
                    icon: 'none'
                });
            } else {
                uni.navigateTo({
                    url: '/pages/gatheringAuth/wxCodeAuth/index'
                });
            }
        },

        // wx实名认证
        goZfbCode() {
            if (this.incomingInfo.status != 4) {
                uni.showToast({
                    title: '请先完成商户认证',
                    icon: 'none'
                });
            } else {
                uni.navigateTo({
                    url: '/pages/gatheringAuth/zfbCodeAuth/index'
                });
            }
        },

        getIncoming(storeId) {
            // 获取进件（盒子商户）信息
            _request
                .get('/box/getIncoming', {
                    storeId: storeId
                })
                .then((res) => {
                    if (res.data.code === 200) {
                        const data = res.data.data;
                        this.setData({
                            incomingInfo: data
                        });
                        console.log(this);
                    }
                });
        },

        // 人工二审状态
        getinstanceInfo() {
            _request
                .get('/box/refreshSecondInstanceStatus', {
                    storeId: uni.getStorageSync('storeId')
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        this.setData({
                            instanceInfo: res.data.data.data
                        });
                    }
                });
        },

        onLoad() {
            console.log('占位：函数 onLoad 未声明');
        }
    }
};
</script>
<style>
/* pages/gatheringAuth/index.wxss */
page {
    padding: 20rpx 30rpx;
}

.titie {
    font-size: 36rpx;
    font-weight: bold;
}

.authbox {
    width: 690rpx;
    padding: 30rpx;
    box-sizing: border-box;
    border-radius: 10px;
    background: #fff;
    position: relative;
    margin-top: 20rpx;
    box-shadow: 2px 2px 10px 2px #e6e6e6;
}

.auth_name {
    font-size: 28rpx;
}

.auth_user {
    font-size: 24rpx;
    color: #666;
    margin-top: 20rpx;
}

.text-r {
    font-size: 24rpx;
    position: absolute;
    top: 30rpx;
    right: 40rpx;
}

.btn {
    border-radius: 44px;
    color: #fff;
    background-color: #ff8722;
    line-height: 60rpx;
    height: 60rpx;
    margin-top: 50rpx;
    width: 180rox;
    min-width: 180rpx;
    text-align: center;
    font-size: 28rpx;
}

.btn1 {
    border-radius: 44px;
    color: #fff;
    background-color: #999;
    line-height: 60rpx;
    height: 60rpx;
    margin-top: 50rpx;
    width: 180rox;
    min-width: 180rpx;
    text-align: center;
    font-size: 28rpx;
}

.refresh {
    color: #fff;
    background-color: #ff8722;
    line-height: 88rpx;
    height: 88rpx;
    font-size: 32rpx;
    text-align: center;
    width: 690rpx;
    border-radius: 44px;
    margin-top: 30rpx;
}

.l-90 {
    line-height: 90rpx;
}

.auth_msg {
    font-size: 22rpx;
    color: #666;
    margin-top: 20rpx;
}
</style>
